﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.Data;
using BEGDC.Utility.NHibernate;
using Castle.Services.Transaction;
using System.Collections;
using System.Xml;
using Castle.Facilities.NHibernateIntegration;

namespace BEGDC.PreContract.BLL
{
	public partial class OperationLog: IOperationLog
	{
        public enum OperationType
        {
            Login,
            ImportPreContract,
            ImportDelivery,
            ImportOrion,
            ImportTransfer,
            ImportComments,
            EditPreContract,
            EditUser,
            EditCloseDate,
            EditExchangeRate,
            EditDeadline,
            SendEmail,
            IAM
        }

        //Get Last Login time
        //Joan 2008-09-17
        [Transaction(TransactionMode.Requires)]
        public string GetLastLoginTime(string filter)
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql = "SELECT Top 1 OperationDate  FROM OperationLog";
                if (filter != string.Empty)
                    strSql += " WHERE " + filter;
                strSql += " ORDER BY OperationDate DESC";

                DataTable dtSearch = DAO.ExecuteDataTable(session, strSql);
                if (dtSearch.Rows.Count > 0)
                    return dtSearch.Rows[0][0].ToString();
                else
                    return string.Empty;
            }
        }

        //joan 2008-10-10 
        //Get operation log list based on all operations  or only last operation
        [Transaction(TransactionMode.Requires)]
        public DataTable GetOperationLogs(string filter, bool allOperation)
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql;
                if (allOperation) //all
                {
                    strSql = "SELECT * FROM OperationLog";
                }
                else //last
                {
                    strSql = "SELECT * FROM vw_LastOperation ";
                }

                //strSql = "SELECT * FROM OperationLog";
                if (filter != string.Empty)
                    strSql += " WHERE " + filter;

                DataTable dtSearch = DAO.ExecuteDataTable(session, strSql);

                return dtSearch;
            }
        
        }

	}
}



